﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.InfoCards.GetLedgerEntryForRecipientRequest
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 8E14765A-6610-409A-BA36-099A0642905D
// Assembly location: E:\git\ALLIDA\windll\infocard.exe

using Microsoft.InfoCards.Diagnostics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Microsoft.InfoCards
{
  internal class GetLedgerEntryForRecipientRequest : UIAgentRequest
  {
    private Uri m_cardId;
    private string m_recipientId;
    private byte[] m_bytes;

    public GetLedgerEntryForRecipientRequest(
      IntPtr rpcHandle,
      Stream inArgs,
      Stream outArgs,
      ClientUIRequest parent)
      : base(rpcHandle, inArgs, outArgs, parent)
    {
    }

    protected override void OnMarshalInArgs()
    {
      InfoCardTrace.Assert(this.InArgs.Length > 0L, "The user preferences must be specified");
      BinaryReader reader = (BinaryReader) new InfoCardBinaryReader(this.InArgs, Encoding.Unicode);
      this.m_cardId = Utility.DeserializeUri(reader);
      this.m_recipientId = Utility.DeserializeString(reader);
    }

    protected override void OnProcess()
    {
      InfoCardTrace.Assert((Uri) null != this.m_cardId, "The card Id must not be null");
      InfoCardTrace.Assert(!string.IsNullOrEmpty(this.m_recipientId), "The thumbPrint must be specified");
      List<QueryParameter> queryParameterList = new List<QueryParameter>();
      queryParameterList.Add(new QueryParameter("ix_objecttype", new object[1]
      {
        (object) -1
      }));
      queryParameterList.Add(new QueryParameter("ix_parentid", new object[1]
      {
        (object) GlobalId.DeriveFrom(this.m_cardId.ToString())
      }));
      queryParameterList.Add(new QueryParameter("ix_name", new object[1]
      {
        (object) this.m_recipientId
      }));
      StoreConnection connection = StoreConnection.GetConnection();
      try
      {
        DataRow singleRow = connection.GetSingleRow(queryParameterList.ToArray());
        if (singleRow == null)
          return;
        this.m_bytes = singleRow.GetDataField();
      }
      finally
      {
        connection.Close();
      }
    }

    protected override void OnMarshalOutArgs()
    {
      if (this.m_bytes == null)
        return;
      this.OutArgs.Write(this.m_bytes, 0, this.m_bytes.Length);
    }
  }
}
